maxlength=4;

edgecombinations = {};

for i=2:maxlength
    combinations = combn([0,1],i);
    for j=1:size(combinations,1)
        data = combinations(j,:);
        edges = ManchesterPeriod(data);
        if size(edges,2) == 0 || data(1) == 0
            continue
        end
        edgecombinations{end+1} = mat2str(edges);
        %disp(['Data: ', mat2str(data), ' - Periods between falling edges: ', mat2str(edges)]);
        reconstructed = ManchesterDecode(edges);
        %disp(['Reconstructed ', mat2str(reconstructed), ' - data ', mat2str(data)]);
        if size(reconstructed,2) ~= size(data,2) || ~isequal(reconstructed, data)
            disp(['Reconstructed ', mat2str(reconstructed), ' did not match input ', mat2str(data)]);
        end
    end
end

u = unique(edgecombinations);

if size(u,2) ~= size(edgecombinations,2)
    disp('Duplicates detected');    
else
    disp('No duplicates detected');
end
        
% Todo:
    % handle LSB first 
    % handle parity bit
    % expect -> S , n * (8 + p) bits, E
    % for some commands n * (8 + p) includes a CRC
    % With above information we always know how much bits we're missing
